import {
  response,
  errorHandle,
  url
} from './response';

const getToken = () => {
  return wx.getStorageSync('auth');
}
/**
 * 编号添加
 * @param {*} data 
 * @param {*} successCallback 
 */
export const add = (data, successCallback) => {
    wx.request({
      url: `${url}/numSettings/add`,
      method: 'post',
      data,
      header: {
        'x-user-agent': 'miniprogram',
        'x-auth-token': getToken()
      },
      success(res) {
        response(res, successCallback);
      },
      fail: (res) => {
        errorHandle(res.errMsg);
      }
    })
  }
/**
 * 编号移除
 * @param {*} data 
 * @param {*} successCallback 
 */
export const remove = (data, successCallback) => {
  wx.request({
    url: `${url}/numSettings/remove`,
    method: 'post',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}
/**
 * 编号列表
 * @param {*} data 
 * @param {*} successCallback 
 */
export const list = (data, successCallback) => {
  wx.request({
    url: `${url}/numSettings/list`,
    method: 'get',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}
/**
 * 编号搜索
 * @param {*} data 
 * @param {*} successCallback 
 */
export const search = (data, successCallback) => {
  wx.request({
    url: `${url}/numSettings/search`,
    method: 'get',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}
/**
 * 编号更新
 * @param {*} data 
 * @param {*} successCallback 
 */
export const update = (data, successCallback) => {
  wx.request({
    url: `${url}/numSettings/update`,
    method: 'post',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}
/**
 * 编号详情
 * @param {*} data 
 * @param {*} successCallback 
 */
export const _get = (id, successCallback) => {
  wx.request({
    url: `${url}/numSettings/${id}`,
    method: 'get',
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}

 